package com.lwl.Algorithmic_data_structure.class12二叉树;

import java.util.Arrays;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lwl
 * @Description TODO
 * @date 2023/12/19 18:45
 */
public class TEST {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("interrupted");
                    return;
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("sleep");
                }
            }

        });
//        thread.start();
//        Thread.sleep(2000);
//        thread.interrupt();
//        invoke(1);
//        ScheduledThreadPoolExecutor poolExecutor = new ScheduledThreadPoolExecutor(1);
//        schedule(poolExecutor);
//        poolExecutor.shutdown();
        test1();
        System.out.println("---");
        test2();
        System.out.println("---");
        test3();
    }

    public static void test3(){
        int a = 0,b = 0;
        int[] array = {1,2,3,4};
        Arrays.stream(array).filter(item ->{
            if (item % 2 == 0){
                System.out.println(item);
                return true;
            }
            return false;
        }).anyMatch(item ->{
            System.out.println(item);
            return item / 2 == 2;
        });
    }
    public static void test2(){
        int[] array = {1,2,3,4};
        Arrays.stream(array).filter(item ->{
            if (item % 2 == 0){
                System.out.println(item);
                return true;
            }
            return false;
        }).forEach(System.out::println);
    }
    public static void test1(){
        int[] array = {1,2,3,4};
        Arrays.stream(array).filter(item ->{
            if (item % 2 == 0){
                System.out.println(item);
                return true;
            }
            return false;
        });
    }


    static void schedule(ScheduledThreadPoolExecutor poolExecutor){

        poolExecutor.schedule(()->{
            int n = 1/0;
            System.out.println(n);
        },10, TimeUnit.NANOSECONDS);
    }

    private static void invoke(Integer value){
        System.out.println(1);
    }
    private static void invoke(int value,Object... args) {
        System.out.println(2);
    }

    private static void invoke(Integer value,Object... args) {
        System.out.println(3);
    }
}
